package com.bwie.service.impl;

import cn.hutool.core.util.StrUtil;
import com.alibaba.csp.sentinel.eagleeye.EagleEye;
import com.bwie.common.domain.Users;
import com.bwie.mapper.UserMapper;
import com.bwie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.annotation.ElementType;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Users login(String tel) {
        return userMapper.login(tel);
    }

    @Override
    public void add(Users users) {
        String tel = users.getTel();
        String password = users.getPassword();
        String username = users.getUsername();
        String poss = users.getPoss();
        if(StrUtil.isBlank(tel)){
            throw new RuntimeException("手机号不能为空");
        }
        if (!tel.matches("1[3-9][0-9]{9,}")) {
            throw new RuntimeException("手机号格式不正确");
        }
        if (StrUtil.isBlank(password)) {
            throw new RuntimeException("密码不能为空");
        }
        if(StrUtil.isBlank(username)){
            throw new RuntimeException("用户名不能为空");
        }
        if(StrUtil.isBlank(poss)){
            throw new RuntimeException("密码不正确");
        }
        if(!password.matches(poss)){
            throw new RuntimeException("密码不匹配");
        }
        userMapper.add(users);
    }
}
